import 'package:dio/dio.dart';
import 'package:f_demo_one/components/20_dio_shop_list.dart';
import 'package:f_demo_one/components/22_%E5%95%86%E5%93%81%E5%88%97%E8%A1%A8%E7%BB%84%E4%BB%B6.dart';
import 'package:flutter/material.dart';

class MyApp22 extends StatefulWidget {
  const MyApp22({super.key});

  @override
  State<MyApp22> createState() => _MyApp20State();
}

class _MyApp20State extends State<MyApp22> {
  List goodsList = [];

  @override
  void initState() {
    super.initState();
    getData();
  }

  void getData() async {
    Dio dio = Dio();
    final res = await dio.get(
      'https://m1.apifoxmock.com/m1/6883141-6598682-default/zgl/orders',
    );
    setState(() {
      goodsList = res.data;
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('商品订单信息'),
        centerTitle: true,
        backgroundColor: const Color.fromARGB(255, 75, 163, 78),
      ),
      body: ListView.separated(
        itemBuilder: (BuildContext context, int index) {
          return DioShopList22(goods: goodsList[index]);
        },
        separatorBuilder: (BuildContext context, int index) {
          return Container(
            margin: EdgeInsets.only(left: 10, right: 10),
            child: Divider(height: 1, color: Colors.blue),
          );
        },
        itemCount: goodsList.length,
      ),
    );
  }
}
